package sort;

import java.util.Arrays;

/**
 * 插入排序
 */
public class InsertSort {
    public static void main(String[] args) {
        Integer [] arr = new Integer[]{9,2,3,1,5};
        System.out.println(Arrays.toString(insert(arr)));
    }

    public static Integer[] insert(Integer [] arr){

        for (int i = 0; i < arr.length-1; i++) {
                int j = i+1;
                int temp = arr[j];
                while (j>0 &&  temp < arr[j-1]){
                    arr[j] = arr[j-1];
                    j--;
                }
                arr[j] = temp;
            }
        return arr;
    }

}
